import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/modules/application/education/personal_profile/personal_profile_controller.dart';

class EducationProfileBasicController extends GetxController {
  final profile = Get.find<EducationProfileController>();

  final nameCtrl = TextEditingController();
  final phoneCtrl = TextEditingController();
  final idCtrl = TextEditingController();
  final schoolCtrl = TextEditingController();
  final majorCtrl = TextEditingController();
  final emailCtrl = TextEditingController();

  /// 性别 0男 1女 2保密
  var _sex = 2;
  String get sex {
    switch (_sex) {
      case 0:
        return '男';
      case 1:
        return '女';
      default:
        return '保密';
    }
  }

  set sex(String sexName) {
    switch (sexName) {
      case '男':
        _sex = 0;
        break;
      case '女':
        _sex = 1;
        break;
      case '保密':
        _sex = 2;
        break;
    }
  }

  /// 学历
  String? education = '';

  /// 学位
  String? degree = '';

  void onProfileChanged() {
    nameCtrl.text = profile.entity?.nickname ?? '';
    phoneCtrl.text = profile.entity?.mobile ?? '';
    idCtrl.text = profile.entity?.idNo ?? '';
    schoolCtrl.text = profile.entity?.school ?? '';
    majorCtrl.text = profile.entity?.professionalName ?? '';
    emailCtrl.text = profile.entity?.email ?? '';
    _sex = profile.entity?.sex ?? 2;
    education = profile.entity?.education;
    degree = profile.entity?.academicDegree;
    update();
  }

  void onSaveChanges() {
    profile.entity?.nickname = nameCtrl.text;
    profile.entity?.mobile = phoneCtrl.text;
    profile.entity?.idNo = idCtrl.text;
    profile.entity?.school = schoolCtrl.text;
    profile.entity?.professionalName = majorCtrl.text;
    profile.entity?.email = emailCtrl.text;
    profile.entity?.sex = _sex;
    if (education != null) profile.entity?.education = education!;
    if (degree != null) profile.entity?.academicDegree = degree!;
  }
}
